# Importing Data
CHINA<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Magnesium/Magnesium.xlsx",sheet = "Sheet1", range = "C1:C264")

# Checking the Imported Data
View(CHINA)
# Creating Time Series Data
CHINA_ts <- ts(CHINA, start=c(1998,1), end=c(2018,12), frequency=12)
# Viewing and Checking the Created Time Series Data
CHINA_ts
sum(is.na(CHINA_ts))
library(forecast)
CHINA_ts <- tsclean(CHINA_ts)
CHINA_ts

# Identification: Plotting the Time Series Data
plot(CHINA_ts)

# Estimating the appropriate model
CHINA_ts_model <- auto.arima(CHINA_ts)
CHINA_ts_model

# Forecasting
options(max.print=1000000)
CHINA_ts_forecast <- forecast (CHINA_ts_model, level=c(95), h=264)
plot(CHINA_ts_forecast)
CHINA_ts_forecast             

# Exporting
write.table(CHINA_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Magnesium/CHINA_TSA.csv", sep=",")
